﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="SanPham.ascx.cs" Inherits="SanPham" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<center>
    <asp:Panel ID="pnGridDetail" runat="server" Width="100%">
        <span class="BigLabel2">DANH SÁCH SẢN PHẨM ĐÃ KHAI BÁO</span><br />
        <asp:TextBox Width="165px" runat="server" ID="txtTuKhoa" onfocus="if(this.value=='Nhập từ khóa')this.value=''"
            onblur="if(this.value=='')this.value='Nhập từ khóa'" value="Nhập từ khóa"></asp:TextBox>
        <asp:DropDownList Width="165px" runat="server" ID="cboParent" DataTextField="Name"
            DataValueField="Id" AutoPostBack="True" OnSelectedIndexChanged="cboParent_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:DropDownList Width="165px" runat="server" ID="cboGroup" DataTextField="Name"
            DataValueField="Id" AutoPostBack="True" OnSelectedIndexChanged="cboGroup_SelectedIndexChanged">
            <asp:ListItem Text="- Tất cả các dòng bút -" Value="-1"></asp:ListItem>
        </asp:DropDownList>
        <asp:DropDownList Width="165px" runat="server" ID="cboLoai" DataTextField="Name"
            DataValueField="Id" AutoPostBack="True" OnSelectedIndexChanged="cboLoai_SelectedIndexChanged">
        </asp:DropDownList>
        <asp:DropDownList Width="165px" runat="server" ID="cboGia" DataTextField="Name" 
            DataValueField="Id" onselectedindexchanged="cboGia_SelectedIndexChanged">
        </asp:DropDownList>
        &nbsp;
        <asp:Button runat="server" ID="cmdSearch" Text="Tìm kiếm" OnClick="cmdSearch_Click" />
        <asp:SqlDataSource ID="dsNhomHangLoc" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
            ProviderName="<%$ ConnectionStrings:DBConnectionString.ProviderName %>"></asp:SqlDataSource>
        <asp:DataGrid ID="detailGrid" runat="server" AllowPaging="false" AutoGenerateColumns="False"
            OnItemCommand="detailGrid_ItemCommand" OnItemDataBound="detailGrid_ItemDataBound"
            OnPageIndexChanged="detailGrid_PageIndexChanged" Width="100%" PageSize="5">
            <PagerStyle Mode="NumericPages" />
            <Columns>
                <asp:BoundColumn Visible="False" HeaderText="id" DataField="id"></asp:BoundColumn>
                <asp:BoundColumn HeaderText="<span>Mã h&#224;ng</span></span>" DataField="seri"></asp:BoundColumn>
                <asp:TemplateColumn HeaderText="<span>SP Mới</span>">
                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                    <ItemTemplate>
                        <img width="220" src="<%#Eval("picurl") %>" />
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:BoundColumn HeaderText="<span>T&#234;n h&#224;ng</span>" DataField="TenHang"></asp:BoundColumn>
                <asp:BoundColumn HeaderText="<span>Quà tặng</span>" DataField="QuaTang"></asp:BoundColumn>
                <asp:BoundColumn Visible="False" HeaderText="<span>T&#243;m tắt</span>" DataField="TomLuoc"></asp:BoundColumn>
                <asp:BoundColumn HeaderText="<span>M&#227; nh&#243;m</span>" DataField="NhomId" Visible="False"></asp:BoundColumn>
                <asp:BoundColumn HeaderText="<span>T&#234;n nh&#243;m</span>" DataField="TenNhom"></asp:BoundColumn>
               
                <asp:TemplateColumn HeaderText="<span>Gi&#225; b&#225;n</span>">
			        <HeaderStyle HorizontalAlign="Center" CssClass="HeaderRow"></HeaderStyle>
				    <ItemStyle HorizontalAlign="Right"></ItemStyle>
			        <ItemTemplate>
			            <%#TTQT.TTQT_Code.TTQTCommon.formatTien_KhongThapPhan(Eval("GiaBanThamKhao").ToString())%>
			        </ItemTemplate>
			    </asp:TemplateColumn>
                
                <asp:BoundColumn HeaderText="<span>Ng&#224;y cập nhật</span>" DataField="NgayNhap"></asp:BoundColumn>
                <asp:BoundColumn HeaderText="<span>SP mới</span>" DataField="hangmoi" Visible="False"></asp:BoundColumn>
                <asp:BoundColumn HeaderText="<span>SP đặc biệt</span>" DataField="spHot" Visible="False"></asp:BoundColumn>
                <asp:BoundColumn HeaderText="<span>SP Bán chạy</span>" DataField="BanChay" Visible="False"></asp:BoundColumn>
                <asp:BoundColumn HeaderText="<span>Còn hàng</span>" DataField="conHang" Visible="False"></asp:BoundColumn>
                <asp:TemplateColumn HeaderText="<span>SP Mới</span>">
                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                    <ItemTemplate>
                        <asp:ImageButton runat="server" ID="cmdNew" CommandName="cmdNew" ToolTip="Sản phẩm mới" />
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn HeaderText="<span>SP Đặc biệt</span>">
                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                    <ItemTemplate>
                        <asp:ImageButton runat="server" ID="cmdHot" CommandName="cmdHot" ToolTip="Sản phẩm hot" />
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn HeaderText="<span>SP Bán chạy</span>">
                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                    <ItemTemplate>
                        <asp:ImageButton runat="server" ID="cmdBanChay" CommandName="cmdBanChay" ToolTip="Sản phẩm bán chạy" />
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn HeaderText="<span>Còn hàng</span>">
                    <ItemStyle HorizontalAlign="Center"></ItemStyle>
                    <ItemTemplate>
                        <asp:ImageButton runat="server" ID="cmdConHang" CommandName="cmdConHang" ToolTip="Còn hàng" />
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn>
                    <ItemTemplate>
                        <asp:Button CausesValidation="False" ID="cmdEdit" runat="server" Text="sửa" Width="40"
                            CommandName="cmdEdit"></asp:Button>
                    </ItemTemplate>
                </asp:TemplateColumn>
                <asp:TemplateColumn>
                    <ItemTemplate>
                        <asp:Button CausesValidation="False" ID="cmdDelete" runat="server" Text="Xóa" Width="40"
                            CommandName="cmdDelete" OnClientClick="return confirm('Bạn có chắc muốn xóa sản phẩm này?');">
                        </asp:Button>
                    </ItemTemplate>
                </asp:TemplateColumn>
            </Columns>
            <HeaderStyle CssClass="HeaderRow" Font-Bold="True" />
        </asp:DataGrid>
        <br />
        <asp:Button runat="server" ID="cmdAddDetail" Text="Thêm sản phẩm" OnClick="cmdAddDetail_Click" />
        <asp:SqlDataSource ID="dsDetail" runat="server" ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
            ProviderName="<%$ ConnectionStrings:DBConnectionString.ProviderName %>"></asp:SqlDataSource>
    </asp:Panel>
    <asp:Panel ID="pnEditDetail" runat="server" Width="700px">
        <table width="100%" class="TableStyle" cellpadding="0" cellspacing="1">
            <tr>
                <td colspan="2" align="center">
                    <span class="BigLabel2" id="chiTietHoaDon">CHI TIẾT SẢN PHẨM</span>
                </td>
            </tr>
            <tr class="TrStyle">
                <td colspan="2" align="center">
                    <asp:Label runat="server" ID="lblId"></asp:Label>
                </td>
            </tr>
            <tr class="TrStyle">
                <td class="TdStyle" width="120" style="text-align: left">
                    Thương hiệu
                </td>
                <td class="TdStyle" style="text-align: left; width: 240px;">
                    <asp:DropDownList ID="cboParent0" runat="server" AutoPostBack="True" DataTextField="Name"
                        DataValueField="Id" OnSelectedIndexChanged="cboParent0_SelectedIndexChanged"
                        Width="165px">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr class="TrStyle">
                <td class="TdStyle" style="text-align: left" width="120">
                    Dòng sản phẩm
                </td>
                <td class="TdStyle" style="text-align: left; width: 240px;">
                    <asp:DropDownList ID="cboGroup0" runat="server" DataTextField="Name" DataValueField="Id"
                        Width="165px" OnSelectedIndexChanged="cboGroup0_SelectedIndexChanged" AutoPostBack="True">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr class="TrStyle">
                <td style="height: 26px; text-align: left" width="120">
                    Loại sản phẩm
                </td>
                <td style="height: 26px; text-align: left" width="120">
                    <asp:DropDownList ID="cboLoai0" runat="server" DataTextField="Name" DataValueField="Id"
                        Width="165px" AutoPostBack="True" OnSelectedIndexChanged="cboLoai0_SelectedIndexChanged">
                    </asp:DropDownList>
                    &nbsp;Xuất xứ:
                    <asp:DropDownList ID="cboNoiSX0" runat="server" DataTextField="NoiSX" DataValueField="Id"
                        Width="165px" AutoPostBack="True">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr class="TrStyle">
                <td style="height: 26px; text-align: left" width="120">
                    Mã sản phẩm
                </td>
                <td style="height: 26px; text-align: left" width="120">
                    <asp:TextBox ID="txtSeri" runat="server" Width="300px"></asp:TextBox>
                </td>
            </tr>
            <tr class="TrStyle">
                <td style="height: 26px; text-align: left" width="120">
                    Tên hàng
                </td>
                <td style="height: 26px; text-align: left" width="120">
                    <asp:TextBox ID="txtTenHang" runat="server" Width="300px"></asp:TextBox>
                </td>
            </tr>
            <tr class="TrStyle">
                <td style="height: 26px; text-align: left" width="120">
                    Quà tặng kèm
                </td>
                <td style="height: 26px; text-align: left" width="120">
                    <asp:TextBox ID="txtQuaTang" runat="server" Width="300px"></asp:TextBox>
                </td>
            </tr>
            <tr class="TrStyle">
                <td style="height: 26px; text-align: left" width="120">
                    Giá bán
                </td>
                <td style="height: 26px; text-align: left" width="120">
                    <asp:TextBox ID="txtGiaBanThamKhao" runat="server" Width="300px"></asp:TextBox>
                </td>
            </tr>
            <tr class="TrStyle">
                <td style="height: 26px; text-align: left" width="120">
                    Chiết khấu(%)
                </td>
                <td style="height: 26px; text-align: left" width="120">
                    <asp:TextBox ID="txtChietKhau" runat="server" Width="100px"></asp:TextBox>&nbsp;Giá
                    bán có chiết khấu:
                    <asp:TextBox ID="txtGiaBanCoChietKhau" runat="server" Width="100px"></asp:TextBox>
                </td>
            </tr>
            <tr class="TrStyle">
                <td style="height: 26px; text-align: left" width="120">
                    Là sản phẩm hot
                </td>
                <td style="height: 26px; text-align: left" width="120">
                    <asp:CheckBox runat="server" ID="chkHangMoi" Text="Sản phẩm mới" />
                    <asp:CheckBox runat="server" ID="chkSPHot" Text="SP hot" />
                    <asp:CheckBox runat="server" ID="chkBanChay" Text="Sản phẩm bán chạy" />
                    <asp:CheckBox runat="server" ID="chkConHang" Text="Còn hàng" />
                </td>
            </tr>
            <tr class="TrStyle">
                <td style="height: 26px; text-align: left" width="120">
                    Upload ảnh
                </td>
                <td style="height: 26px; text-align: left" width="120">
                    <asp:FileUpload runat="server" ID="anh" />
                    <asp:Button runat="server" ID="cmdUpload" Text="Upload" OnClick="cmdUpload_Click" />
                </td>
            </tr>
            <tr class="TrStyle">
                <td style="height: 26px; text-align: left" width="120">
                    &nbsp;
                </td>
                <td style="height: 26px; text-align: left" width="120">
                    <asp:Label runat="server" ID="lblPathAnh" Visible="False"></asp:Label>
                    <asp:Image runat="server" ID="imgUpload" />
                    <br />
                    <br />
                    <asp:LinkButton runat="server" ID="cmdXoaAnh" Text="Xóa ảnh" OnClientClick="return confirm('Bạn có chắc muốn xóa?')"
                        OnClick="cmdXoaAnh_Click" Visible="False"></asp:LinkButton>
                    <br />
                </td>
            </tr>
            <tr class="TrStyle">
                <td style="height: 34px; text-align: left" width="120">
                    Tóm lược
                </td>
                <td style="height: 34px; text-align: left">
                    <asp:TextBox ID="txtTomLuoc" runat="server" TextMode="MultiLine" Width="99%" Height="100px"></asp:TextBox>
                </td>
            </tr>
            <tr class="TrStyle">
                <td style="height: 34px; text-align: left" width="120">
                    Nội dung
                </td>
                <td style="height: 34px; text-align: left">
                    <FCKeditorV2:FCKeditor ID="fck" runat="server" BasePath="~/fckeditor/" Width="620px"
                        Height="600px">
                    </FCKeditorV2:FCKeditor>
                </td>
            </tr>
            
            <tr class="TrStyle">
                <td style="height: 34px; text-align: left" width="120">
                    Các thông số kỹ thuật
                </td>
                <td style="height: 34px; text-align: left">
                    <FCKeditorV2:FCKeditor ID="fckThongSo" runat="server" BasePath="~/fckeditor/" Width="620px"
                        Height="380px">
                    </FCKeditorV2:FCKeditor>
                </td>
            </tr>
            
            
            
            <tr class="TrStyle">
                <td colspan="2" style="height: 26px; text-align: center">
                    <asp:Label ID="lblErrorChiTiet" runat="server" ForeColor="Red"></asp:Label>
                </td>
            </tr>
            <tr class="TrStyle">
                <td colspan="2" style="height: 26px; text-align: center">
                    <asp:Button ID="cmdCapNhatDetail" runat="server" OnClick="cmdCapNhatDetail_Click"
                        Text="Cập nhật" />
                    <asp:Button ID="cmdHuyBoDetail" runat="server" Text="Thoát" OnClick="cmdHuyBoDetail_Click" />
                </td>
            </tr>
        </table>
    </asp:Panel>
</center>

<script language="javascript" type="text/javascript">
    function ckLostFocus() {
        var giaGoc = document.getElementById('<%=txtGiaBanThamKhao.ClientID%>').value;
        while (giaGoc.indexOf(',') >= 0) {
            giaGoc = giaGoc.replace(',', '');
        }
        //alert(giaGoc);
        var ck = document.getElementById('<%=txtChietKhau.ClientID%>').value;
        while (ck.indexOf(',') >= 0) {
            ck = ck.replace(',', '');
        }
        if (ck > 100) {
            alert('Chiet khau khong the lon hon 100%');
            document.getElementById('<%=txtChietKhau.ClientID%>').value = 0;
            document.getElementById('<%=txtGiaBanCoChietKhau.ClientID%>').value = document.getElementById('<%=txtGiaBanThamKhao.ClientID%>').value;
            return false;
        }
        //alert(ck);
        var giaBan = document.getElementById('<%=txtGiaBanThamKhao.ClientID%>').value;
        while (giaBan.indexOf(',') >= 0) {
            giaBan = giaBan.replace(',', '');
        }
        giaBan = giaGoc - (giaGoc * ck / 100);
        //alert(giaBan);
        giaBan = '' + giaBan;
        //alert(formatStringTien(giaBan));
        document.getElementById('<%=txtGiaBanCoChietKhau.ClientID%>').value = formatStringTien(giaBan);
    }
    function gbLostFocus() {
        var giaGoc = document.getElementById('<%=txtGiaBanThamKhao.ClientID%>').value;
        while (giaGoc.indexOf(',') >= 0) {
            giaGoc = giaGoc.replace(',', '');
        }
        //alert(giaGoc);
        var ck = document.getElementById('<%=txtChietKhau.ClientID%>').value;
        while (ck.indexOf(',') >= 0) {
            ck = ck.replace(',', '');
        }
        if (ck > 100) {
            alert('Chiet khau khong the lon hon 100%');
            return false;
        }
        //alert(ck);
        var giaBan = document.getElementById('<%=txtGiaBanCoChietKhau.ClientID%>').value;
        while (giaBan.indexOf(',') >= 0) {
            giaBan = giaBan.replace(',', '');
        }
        ck = 100 * (giaGoc - giaBan) / giaGoc;
        ck = lamTronSo(ck, 2);
        //alert(giaBan);
        ck = '' + ck;
        //alert(formatStringTien(giaBan));
        document.getElementById('<%=txtChietKhau.ClientID%>').value = ck;
        document.getElementById('<%=txtGiaBanCoChietKhau.ClientID%>').value = formatStringTien(giaBan);
    }
    $(document).ready(function()
    {
      $("#_ctl2_detailGrid tr:odd").css("background-color", "#FCFBDB");
    });
</script>

